grep Pocket Reference by John Bambenek & Agnieszka Klus

grep Pocket Reference by John Bambenek & Agnieszka Klus

Author:John Bambenek & Agnieszka Klus [Bambenek, John & Klus, Agnieszka]
Language: eng
Format: epub, mobi
Tags: COMPUTERS / Operating Systems / UNIX
ISBN: 9780596157906
Publisher: O'Reilly Media, Inc.


egrep 'patt(a|e)rn' filename

Without the parentheses, the search pattern would be patta|ern, which would match if the string “patta” or “ern” is found, a very different outcome than the intention.

In basic regular expressions, the backslash (\) negates the metacharacter’s behavior and forces the search to match the character in a literal sense. The same happens in egrep, but there is an exception. The metacharacter { is not supported by the traditional egrep. Although some versions interpret \{ literally, it should be avoided in egrep patterns. Instead, [{] should be used to match the character without invoking the special meaning.

It is not precisely true that basic grep does not have these metacharacters as well. It does, but they cannot be used directly. Each of the special metacharacters in extended regular expressions needs to be prefaced by an escape to draw out its special meaning. Note that this is the reverse of normal escaping behavior, which usually strips special meaning.

Table 1-3 illustrates how to use the extended regular expressions metacharacters with basic grep.

Table 1-3. Basic versus extended regular expressions comparison

Basic regular expressions

Extended regular expressions



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.